package com.acwing.lc.part1;

/**
 * @author rkc
 * @date 2022/9/15 10:06
 */
public class LC48旋转图像 {

    public void rotate(int[][] matrix) {
        int n = matrix.length;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < i; j++) {
                swap(matrix, i, j, j, i);
            }
        }
        for (int i = 0; i < n; i++) {
            for (int j = 0, k = n - 1; j < k; j++, k--) {
                swap(matrix, i, j, i, k);
            }
        }
    }

    private void swap(int[][] arr, int x1, int y1, int x2, int y2) {
        int t = arr[x1][y1];
        arr[x1][y1] = arr[x2][y2];
        arr[x2][y2] = t;
    }
}
